home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / repmaker.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  6KB  |  204 lines

  1. #include <stdlib.h>
  2. #include "repmaker.h"
  3. #include "text_buf.h"
  4.  
  5. int ReportMaker::get_command(char* buf, int i, ADD_LIST* info,
  6.     FIELD_LIST* flist)
  7.     {
  8.     i++;                    // Skip @
  9.     ADDINFO_LAYOUT* add;
  10.     switch(buf[i])
  11.         {
  12.         case 'd':           // date
  13.             add = new ADDINFO_LAYOUT(loc(i - 1, bline), DATE_INFO,
  14.                 "");
  15.             add->service[5] = 0;
  16.             info->add(add, info->used_add);
  17.             i += 4;
  18.             break;
  19.     case 'D':           // dd
  20.             add = new ADDINFO_LAYOUT(loc(i - 1, bline), DATE_INFO,
  21.                 "");
  22.             add->service[5] = 1;
  23.             info->add(add, info->used_add);
  24.             i += 2;
  25.             break;
  26.     case 'M':           // mm
  27.             add = new ADDINFO_LAYOUT(loc(i - 1, bline), DATE_INFO,
  28.                 "");
  29.             add->service[5] = 2;
  30.             info->add(add, info->used_add);
  31.             i += 2;
  32.             break;
  33.     case 'Y':           // yy
  34.             add = new ADDINFO_LAYOUT(loc(i - 1, bline), DATE_INFO,
  35.                 "");
  36.             add->service[5] = 3;
  37.             info->add(add, info->used_add);
  38.             i += 2;
  39.             break;
  40.     case 'n':           // record num
  41.             add = new ADDINFO_LAYOUT(loc(i - 1, bline),
  42.             REC_NO_INFO, "");
  43.             info->add(add, info->used_add);
  44.             i += 2;
  45.             break;
  46.     case 'p':           // page
  47.             add = new ADDINFO_LAYOUT(loc(i - 1, bline), PAGE_INFO,
  48.                 "");
  49.             info->add(add, info->used_add);
  50.             i += 4;
  51.             break;
  52.     default:           // "field name"
  53.             int res = i - 1;
  54.             i++;            // Skip "
  55.             char* tok;
  56.  
  57.             tok = strtok(buf + i, " ");  // tok contains wrap x
  58.             int fno = atoi(tok);
  59.             i += strlen(tok) + 1;
  60.  
  61.             int wrapx = PAGE_WIDTH, wrapy = 1;
  62.  
  63.             FIELD_LAYOUT* fld = new FIELD_LAYOUT(rect(res, bline,
  64.             res + wrapx, bline + wrapy), fno);
  65.             flist->add(fld, flist->used_fields);
  66.             break;
  67.         }
  68.     return i;
  69.     }
  70. ///////////////////////////////
  71. int ReportMaker::get_band(ADD_LIST* info, FIELD_LIST* flist)
  72.     {
  73.     char buf[255];
  74.     int band_top = line;
  75.  
  76.     while(1)        // Skip white and comments
  77.         {
  78.         fgets(buf, 255, f);
  79.         if(!strcmp(buf, "PAGETOP\n")   || !strcmp(buf, "PAGEBOTTOM\n")   ||
  80.            !strcmp(buf, "TABLETOP\n")  || !strcmp(buf, "TABLEBOTTOM\n")  ||
  81.            !strcmp(buf, "RECORDTOP\n") || !strcmp(buf, "RECORDBOTTOM\n") ||
  82.            !strcmp(buf, "RECORD\n"))
  83.            break;
  84.         line++;
  85.         band_top++;
  86.         }
  87.  
  88.     while(1)
  89.         {
  90.         fgets(buf, 255, f);
  91.         if(buf[strlen(buf) - 1] == '\n')
  92.             buf[strlen(buf) - 1] = '\0';
  93.  
  94.         if(!strcmp(buf, "PAGETOP")   || !strcmp(buf, "PAGEBOTTOM")   ||
  95.            !strcmp(buf, "TABLETOP")  || !strcmp(buf, "TABLEBOTTOM")  ||
  96.            !strcmp(buf, "RECORDTOP") || !strcmp(buf, "RECORDBOTTOM") ||
  97.            !strcmp(buf, "RECORD"))
  98.            {
  99.            bline = 0;
  100.        return band_top;
  101.            }
  102.         int res = 0;
  103.         for(int i = 0; i < 255 && buf[i] != '\0'; i++)
  104.             {
  105.             if(buf[i] == '@')
  106.                 {
  107.         buf[i] = '\0';
  108.                 ADDINFO_LAYOUT* add = new ADDINFO_LAYOUT(loc(res, bline),
  109.             TEXT_INFO, buf + res);
  110.  
  111.                 info->add(add, info->used_add);
  112.                 buf[i] = '@';
  113.                 i = get_command(buf, i, info, flist);
  114.                 while(buf[i] == ' ')
  115.                     i++;
  116.                 res = i;
  117.                 }
  118.         }
  119.         buf[strlen(buf) + 1] = '\0';
  120.         buf[strlen(buf)] = '\n';
  121.         ADDINFO_LAYOUT* add = new ADDINFO_LAYOUT(loc(res, bline), TEXT_INFO,
  122.         buf + res);
  123.         info->add(add, info->used_add);
  124.  
  125.         line++;
  126.         bline++;
  127.     }
  128.     }
  129. ///////////////////////////
  130. PAGE_LAYOUT* ReportMaker::getPageLayout(char* fileName)
  131.     {
  132.     if((f = fopen(fileName, "r")) == NULL)
  133.         return NULL;
  134.  
  135.     ADD_LIST* p_top_info = new ADD_LIST();
  136.     ADD_LIST* t_top_info = new ADD_LIST();
  137.     ADD_LIST* r_top_info = new ADD_LIST();
  138.  
  139.     RECORD_LAYOUT* rec = new RECORD_LAYOUT();
  140.  
  141.     ADD_LIST* r_bottom_info = new ADD_LIST();
  142.     ADD_LIST* t_bottom_info = new ADD_LIST();
  143.     ADD_LIST* p_bottom_info = new ADD_LIST();
  144.  
  145.     int pt = get_band(p_top_info);
  146.     int tt = get_band(t_top_info);
  147.     int rt = get_band(r_top_info);
  148.  
  149.     get_band((ADD_LIST*)rec, (FIELD_LIST*)rec);
  150.  
  151.     int rb = get_band(r_bottom_info);
  152.     int tb = get_band(t_bottom_info);
  153.     int pb = get_band(p_bottom_info);
  154.  
  155.     PAGE_LAYOUT* page = new PAGE_LAYOUT(
  156.     pt, // p_band_top
  157.     pb, // p_band_bottom,
  158.     tt, // t_band_top,
  159.     tb, // t_band_bottom*,
  160.     rt, // r_band_top,
  161.     rb, // r_band_bottom,
  162.     p_top_info, p_bottom_info, t_top_info, t_bottom_info, r_top_info,
  163.     r_bottom_info, rec);
  164.  
  165.     fclose(f);
  166.     return page;
  167.     }
  168. //////////////////////////////
  169.  
  170. #include "rep_man.h"
  171. void main()
  172.     {
  173.     if(PXInit() != PXSUCCESS)
  174.     return;
  175.  
  176.     KH_PXTable* table = new KH_PXTable("demo.db");
  177.  
  178.     ReportMaker* rm = new ReportMaker();
  179.  
  180.     PAGE_LAYOUT* page = rm->getPageLayout("work.rpt");
  181.  
  182.     ReportManager* report = new ReportManager(page, table, DRAFT,
  183.     LABELS_AS_IS); // l_format
  184.  
  185.     report->print();
  186.  
  187.     delete table;
  188.  
  189.     delete page->pg_top_info;
  190.     delete page->pg_bottom_info;
  191.     delete page->tb_top_info;
  192.     delete page->tb_bottom_info;
  193.     delete page->rc_top_info;
  194.     delete page->rc_bottom_info;
  195.  
  196.     delete page->record;
  197.  
  198.     delete page;
  199.     delete report;
  200.     delete rm;
  201.  
  202.     PXExit();
  203.     }
  204.